﻿<?php
class Model_ProductAuction extends Zend_Db_Table_Abstract
{
	protected $_name = 'product_auction';
	protected $_primary = 'pa_id';
	//protected $_primary ='cat_id';

	public function createProductAuction ($p_id,$pa_giakhoidiem,$pa_buocgia,$u_id,$pa_giobatdau,$pa_gioketthuc,$pa_giaketthuc,$pa_tinhtrang)
	{
		$rowProductAuction= $this->createRow();
		if ($rowProductAuction) {
			// update the row values
			$rowProductAuction->p_id = $p_id;
			$rowProductAuction->pa_giakhoidiem = $pa_giakhoidiem;
			$rowProductAuction->pa_buocgia = $pa_buocgia;
			$rowProductAuction->u_id = $u_id;				
			$rowProductAuction->pa_giobatdau = $pa_giobatdau;
			$rowProductAuction->pa_gioketthuc = $pa_gioketthuc;
			$rowProductAuction->pa_giaketthuc = $pa_giaketthuc;
			$rowProductAuction->pa_tinhtrang = $pa_tinhtrang;
			$rowProductAuction->save();	 		
			//return the new product			
			return $rowProductAuction;
		} else {
			throw new Zend_Exception("Không thể tạo sản phẩm đấu giá này!!!");
		}
	}
	
	// Lấy các sản phẩm  đấu giá theo pa_tinhtrang	
	public static function getProductAuctionByStatus($pa_tinhtrang)
	{
		$productAuctionModel = new self();
		$select = $productAuctionModel->select();
		$select->order(array('pa_id'))
			   ->where('pa_tinhtrang =?',$pa_tinhtrang);	
		return $productAuctionModel->fetchAll($select);
	}
	
	//Lấy các sản phẩm đấu giá theo ID
	public static function getProductAuctionById($pa_id)
	{
		$productAuctionModel = new self();
		$select = $productAuctionModel->select();
		$select->order(array('pa_id'))
			   ->where('pa_id =?',$pa_id);	
		return $productAuctionModel->fetchAll($select);
	}
	
	public static function getProductAuctionByUId($u_id)
	{
		$productAuctionModel = new self();
		$select = $productAuctionModel->select();
		$select->order(array('pa_id'))
			   ->where('u_id =?',$u_id);	
		return $productAuctionModel->fetchAll($select);
	}
	
	public static function getProductAuctionByPId($p_id)
	{
		$productAuctionModel = new self();
		$select = $productAuctionModel->select();
		$select->order(array('pa_id'))
			   ->where('p_id =?',$p_id);	
		return $productAuctionModel->fetchAll($select);
	}	
	
	public static function getProductAuctionAll()
	{
		$productAuctionModel = new self();
		$select = $productAuctionModel->select();
		$select->order(array('pa_id'));	
		return $productAuctionModel->fetchAll($select);
	}	

	
	public static function getProductAuctionLimit($start,$count)
	{
		$productAuctionModel = new self();
		$select = $productAuctionModel->select();
		$select->order(array('pa_id'))
			   ->limit($start,$count);	
		return $productAuctionModel->fetchAll($select);
	}
	
	
	public static function deleteAuctionById($pa_id)
	{
		$productAuctionModel = new Model_ProductAuction();
		$where = $productAuctionModel->getAdapter()->quoteInto('pa_id = ?', $pa_id);
		if($where){
			$productAuctionModel->delete($where);
		}
		else{
			throw new Zend_Exception("Could not delete order");
		}	
	}
}